<?
	class Event extends CI_Controller
	{
		public function __construct()
		{
			parent::__construct();
			$this->load->model('EventModel');
			$this->load->helper('url');
			$this->load->library('session');
		}
		private final function showView($fileName, $data)
		{
			$l = $this->load;
			$l->view('Templates/header.php', $data);
			$l->view('Events/' . $fileName . '.php', $data);
			$l->view('Templates/footer.php', $data);
		}
		private final function getPostData()
		{
			$i = $this->input;
			$b = $this->EventModel;
			$b->Id = $i->post('id');
			$b->Name = $i->post('name');
			$b->Type = $i->post('type');
			$b->Description = $i->post('description');
			$b->DateFrom = $i->post('dateFrom');
			$b->DateTo = $i->post('dateTo');
			$b->NgoId = $i->post('ngoId');
			return $b;
		}
		public final function create()
		{
			$data['title'] = 'Add an event';
			$data['event'] = $this->EventModel->addEvent($this->getPostData());
			$this->showView('create', $data);
		}
		public final function read($id = null)
		{
			if($id == null)
			{
				$data['title'] = 'View all events';
				$data['events'] = $this->EventModel->getAllEvents();
			}
			else
			{
				$data['title'] = 'View event details';
				$data['events'] = $this->EventModel->getEventById($id);
			}
			$this->showView('read', $data);
		}
		public final function update()
		{
			$data['title'] = 'Update an event';
			$data['event'] = $this->EventModel->updateEvent($this->getPostData());
			$this->showView('update', $data);
		}
		public final function delete()
		{
			$id = $this->input->post('id');
			$data['title'] = 'Remove an event';
			$data['event'] = $this->EventModel->removeEventById($id);
			$this->showView('delete', $data);
		}
		public final function setAssignedBeneficiaries()
		{
			//AJAX.
			$this->EventModel->setAssignedBeneficiaries();
		}
		public final function getAssignedBeneficiaries($ngoId, $eventId)
		{
			//JSON view.
			$v = $this->EventModel->getAssignedBeneficiaries($ngoId, $eventId);
			return $this->load->view($s, true);
		}
		public final function broadcast()
		{
			$p = $this->input->post;
			$e = $p('event');
			switch($p('socalNetwork'))
			{
				case SocialNetwork::FACEBOOK:
					//
				break;
				case SocialNetwork::TWITTER:
					//
				break;
				case SocialNetwork::LINKED_IN:
					//
				break;
			}
		}
	}